define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'pro/activitycategory/index',
                    add_url: 'pro/activitycategory/add',
                    edit_url: 'pro/activitycategory/edit',
                    del_url: 'pro/activitycategory/del',
                    multi_url: 'pro/activitycategory/multi',
                    table: 'gzns_course_category',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'sort',
                sortOrder: "asc",
                queryParams: function (params) {
                    if (!params.filter) {
                        params.filter={}
                    }else {
                        params.filter = JSON.parse(params.filter)
                    }
                    if (!params.op) {
                        params.op={}
                    }else {
                        params.op = JSON.parse(params.op)

                    }
                    params.filter.type = '2';
                    params.op.type = '='
                    params.filter = JSON.stringify(params.filter)
                    params.op = JSON.stringify(params.op)

                    return params;
                },
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'),operate:'Like'},
                        {field: 'img', title: __('Img'), formatter: Table.api.formatter.image,operate:false},
                        {field: 'sort', title: __('Sort')},
                        // {field: 'type', title: __('Type')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});